package cn.tedu.autoshow.website.controller;

import cn.tedu.autoshow.commons.web.JsonResult;
import cn.tedu.autoshow.website.pojo.param.PaperDetailAddNewParam;
import cn.tedu.autoshow.website.service.PaperDetailService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/paper_details")
@Validated
@Slf4j
@Api(tags = "稿件详情管理模块")
public class PaperDetailController {
    @Autowired
    private PaperDetailService paperDetailService;



    public PaperDetailController() {
        log.info("创建控制器对象：AttributeTemplateController");
    }

    // http://localhost:8080/album/add-new
    @PostMapping("/add-new") //@PostMapping限制只能使用post请求获取资源
    @ApiOperation("添加稿件")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Valid PaperDetailAddNewParam paperDetailAddNewParam) {
        log.debug("开始处理【添加稿件详情】的请求，参数：{}",paperDetailAddNewParam);
        paperDetailService.addNew(paperDetailAddNewParam);
        log.debug("处理【添加稿件详情】的请求，完成！");
        JsonResult  jsonResult = new JsonResult();
        jsonResult.setState(1);
        jsonResult.setMessage("添加成功！");
        return jsonResult;
    }

    //http://localhost:8080/album/delete?id=1
    @PostMapping("/delete")
    @ApiOperation("根据ID删除稿件")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paperDetailId",value="稿件详情Id",required = true,dataType = "Long")
    })
    public String delete(@Range(min = 1,message = "根据ID删除稿件详情失败，请提交合法ID值！")
                         @RequestParam Long id) throws Exception{
        "".substring(1000000);
        return null;
    }

    @PostMapping("/update")
    @ApiOperation("修改稿件详情")
    @ApiOperationSupport(order =300)
    public String update(){
        throw new NullPointerException("修改出错了，导致了空指针异常");
    }

    @PostMapping("/list")
    @ApiOperation("查询稿件详情列表")
    @ApiOperationSupport(order =300)
    public String list(){
        throw new RuntimeException("查询出错了，导致出现RuntimeException");
    }


}